class LinkedList(object):
    """description of class"""

    class LinkedListNode(object):
        def __init__(self, value):
            self.next = None
            self.value = value


    def __init__(self):
        self.head = None

    def add(self, value):
        newNode = LinkedList.LinkedListNode(value)

        if self.head is not None:
            newNode.next = self.head
        self.head = newNode

    def reverse(self):
        """Reverses this linked list so that self.head points to what used to be
        the tail and the order of the elements is reversed."""
        prev = None
        cur = self.head

        while cur is not None:
            next = cur.next
            cur.next = prev
            prev = cur
            cur = next

        self.head = prev

    def print_list(self):
        cur = self.head
        while cur is not None:
            print(cur.value, end=',')
            cur =  cur.next
        print() #newline
            
if __name__ == '__main__':
    myLinkedList = LinkedList()
    
    myLinkedList.add(1)
    myLinkedList.add(2)
    myLinkedList.add(3)
    myLinkedList.add(4)
    myLinkedList.add(5)
    myLinkedList.add(6)

    myLinkedList.print_list()

    myLinkedList.reverse()

    myLinkedList.print_list()
            
